/******************************************************************************
Author: Akshay Dixit
Date created: July 10, 2018
Date last modified: June 11, 2020
File Name: 6_in.do
Project: T4D Indonesia 
Purpose: Analysis of community awareness of potential health activities
******************************************************************************/

clear all
set more off

cd "$data"

u "$data/household_data.dta", clear

******************************************************************************

*TD01 - Did […] occur in the village in the past 3 years?

desc td01*
local td td01A td01B td01C td01D td01E td01F td01G td01H td01I td01J td01K td01L td01M td01N td01O
foreach var of local td {
	replace `var' = . if `var' == 98
	replace `var' = 0 if `var' == 3
	*tab `var'
	reg `var' treatment strata1 strata2 strata3, vce(cluster iddesa)
	predict `var'_predicted
	tab treatment, sum(`var'_predicted)
}

tab td04_dumL1
reg td04_dumL1 treatment strata1 strata2 strata3, vce(cluster iddesa)

egen td01_total = rowtotal(td01A td01B td01C td01D td01E td01F td01G td01H td01I td01J td01K td01L td01M td01N td01O), missing 
tab treatment, sum(td01_total)

desc td02*
drop td02_ot*	//All Empty


********************************************************************************

* OUTPUT TABLES

***Label variables***
lab var td01A "Socialization campaign aimed at encouraging women to visit health facility"
lab var td01B "Request for a new ambulance"
lab var td01C "Attempts to improve the stock of drugs/equipments at the health facility"
lab var td01D "Attempts to improve the attitude or performance of health facility staff"
lab var td01E "Public posting of the cost of service at the health facility"
lab var td01F "Community members building or requesting a new health facility"
lab var td01G "Attempts to improve health facility infrastructure"
lab var td01H "Improvement to the road leading to the health facility"
lab var td01I "Attempts to reduce the cost of mother and child health services"
lab var td01J "Creation of a community savings group"
lab var td01K "Improvements to the posyandu"
lab var td01L "Community organized transportation to a health facility"
lab var td01M "Hygiene or cleaning campaign"
lab var td01N "Partnership between midwives and baby dukun"
lab var td01O "Additional staff allocated to this village or the health facility"
lab var td01_total "Total number of potential health activities"


***Produce Excel output***

//Create the table shell
putexcel set "$analysis/awareness of potential health activities.xlsx", replace

putexcel A1=("Outcome") B1=("Treatment Mean") C1=("Control Mean") D1=("Impact") ///
E1=("p-value") F1=("Effect Size") G1=("Sample Size") A19=("Number of Respondents") ///
A20=("Number of villages") B19=(3016) C19=(2985) B20=(100) C20=(100) ///
A22=("Treatment means are regression adjusted") A23=("*** p<0.01, ** p<0.05, * p<0.1") ///
A24=("Outcomes pertain to knowledge of potential health activities")

//Export variable label, regression coefficient, control mean, treatment mean, p-value, sample size
//Effect sizes are exported separately (see below)
local outcomes td01_total td01A td01B td01C td01D td01E td01F td01G td01H td01I td01J td01K td01L td01M td01N td01O
local row = 2
foreach var of local outcomes {
	sleep 2000
	local varlabel : var label `var'
	
	qui reg `var' treatment strata1 strata2 strata3, vce(cluster iddesa)
	
	local p = 2*ttail(e(df_r), abs(_b[treatment]/_se[treatment]))
	local stars
		if `p' < 0.10 local stars = "*" 
		if `p' < 0.05 local stars = "**" 
		if `p' < 0.01 local stars = "***"
	local impact = _b[treatment]
	
	qui sum `var' if treatment == 0
	putexcel A`row' = ("`varlabel'")
	putexcel B`row' = ((_b[treatment]) + (r(mean)))
	putexcel C`row' = (r(mean))
	putexcel D`row' = ("`impact'" + "`stars'")
	putexcel E`row' = (`p')
	putexcel G`row' = (e(N))
	local ++row
}

//Export effect sizes for outcomes that aren't already standardized
local outcomes td01_total td01A td01B td01C td01D td01E td01F td01G td01H td01I td01J td01K td01L td01M td01N td01O
local row = 2
foreach var of local outcomes {
	qui reg `var' treatment strata1 strata2 strata3, vce(cluster iddesa)
	qui sum `var' if treatment == 0
	putexcel F`row' = (_b[treatment]/r(sd))
	local ++row
}

********************************************************************************

clear


